<template>
  <div>
    <el-form label-width="100px" :model="state.form" style="max-width: 700px">

      <el-form-item label="自动关闭时间">
        <el-input v-model.number="state.form.autoClose" clearable>
          <template #append>
            <el-button>分钟</el-button>
          </template>
        </el-input>
        <div class="warning-title">订单创建后,用户如在设定时间内未支付,将自动关闭,建议设置为10~15分钟,0为不限制</div>
      </el-form-item>
      <el-form-item label="自动收货时间">
        <el-input v-model="state.form.autoConfirm" clearable>
          <template #append>天</template>
        </el-input>
        <div class="warning-title">
          商品发货后,用户需自行点击确认收货,如在设定时间内无操作,系统将默认收货,0为关闭自动收货
        </div>
      </el-form-item>
      <el-form-item label="自动评价时间">
        <el-input v-model="state.form.autoComment" clearable>
          <template #append>
            <el-button>天</el-button>
          </template>
        </el-input>
        <div class="warning-title">
          商品发货后,用户需自行点击确认收货,如在设定时间内无操作,系统将默认收货,0为关闭自动收货
        </div>

      </el-form-item>
      <el-form-item label="评价内容">
        <el-input v-model="state.form.autoCommentContent">
        </el-input>
      </el-form-item>


      <el-form-item label="评价内容审核">
        <el-radio-group v-model="state.form.commentCheck">
          <el-radio :value="0" label="审核后展示"></el-radio>
          <el-radio :value="1" label="直接展示"></el-radio>
        </el-radio-group>
        <div class="warning-title" style="width: 100%">
          建议用户评价内容在后台审核后展示,选择直接展示将跳过审核直接发布
        </div>
      </el-form-item>

      <el-form-item label="自动退款审核">
        <el-switch v-model="state.form.autoRefund" :active-value="1" :inactive-value="0" active-text="开启"
                   inactive-text="关闭" inline-prompt>
        </el-switch>
        <div class="warning-title" style="width: 100%">
          未发货订单,用户申请退款后将自动原路退款,并且恢复库存和销量
        </div>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" size="default">
          重置
        </el-button>
        <el-button type="primary" size="default" @click="submit">
          保存
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script setup lang="ts">

import {reactive} from "vue";
import {SettingApi} from "/@/api/shop/setting";
import messageUtils from "/@/utils/messageUtils";

const state = reactive({
  form: {
    autoClose: 10,
    autoComment: 7,
    autoConfirm: 10,
    autoCommentContent: '客户默认给出好评~',
    commentCheck: 0,    //评价审核
    autoRefund: 0,  //
    id: ''
  }
})

const onChoice = async () => {
  try {
    const {data} = await SettingApi().view_order_setting()
    state.form = data
    console.log(data)
  } catch (e) {
    messageUtils().error("操作失败，稍后重试")
  }
}

const submit = async () => {
  try {
    const {data} = await SettingApi().update_order_setting(state.form)
    messageUtils().success("操作成功")
  } catch (e) {
    messageUtils().error("操作失败，请稍后重试")
  }
}


defineExpose({onChoice})
</script>

<style scoped lang="scss">

.warning-title {
  font-size: 12px;
  line-height: 16px;
  color: var(--sd-subfont);
}
</style>